﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace WindowsUserControl.Codes
{
    /// <summary>
    /// 
    /// </summary>
    public class WindowsApplicationContext
    {
        /// <summary>
        /// Gets the dynamic languages lexer path.
        /// </summary>
        /// <value>The dynamic languages lexer path.</value>
        public string DynamicLexersPath
        {
            get
            {
                return Path.Combine(this.ProjectPath, @"Codes\Lexers\");
            }
        }

        /// <summary>
        /// Gets the project path.
        /// </summary>
        /// <value>The project path.</value>
        public string ProjectPath
        {
            get
            {
                return Path.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath));
            }
        }

        /// <summary>
        /// Shows the specified documentation help topic.
        /// </summary>
        /// <param name="topic">The help topic to display.</param>
        public void ShowDocumentationTopic(string topic)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("hh.exe", "Documentation.chm::/" + topic + ".htm");
            startInfo.WorkingDirectory = this.ProjectPath + @"..\";
            Process.Start(startInfo);
        }

        /// <summary>
        /// Represents a simple splash form to display while the cache is built.
        /// </summary>
        public class CacheSplashForm : Form
        {

            /// <summary>
            /// Creates a new instance of the <c>CacheSplashForm</c> class.
            /// </summary>
            public CacheSplashForm()
            {
                this.ControlBox = false;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.ShowInTaskbar = false;
                this.Size = new Size(300, 70);
                this.StartPosition = FormStartPosition.CenterScreen;
                this.Text = null;
                Rectangle clientRect = this.ClientRectangle;
                clientRect.Inflate(-5, -5);

                Label label = new Label();
                label.Bounds = clientRect;
                label.Parent = this;
                label.Text = "Building .NET assembly reflection cache...\r\nIf this is the first time loading this form then it may take several seconds but will be much faster the next time this form loads.";
            }
        }
    }
}
